package com.jic.member.controller.manage;

import com.jic.common.base.vo.RestResult;
import com.jic.member.api.rest.MemberIntegralConsumerApi;
import com.jic.member.provider.service.MememberIntegralExchangeLog;
import com.jic.member.request.MememberIntegralActionRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;

@RestController
@RequestMapping("/memberIntegralConsumerApi")
@Slf4j
public class MemberIntegralConsumerApiController implements MemberIntegralConsumerApi {

    @Resource
    private MememberIntegralExchangeLog mememberIntegralExchangeLog;

    @Override
    public RestResult updMemberIntegralInfo(MememberIntegralActionRequest request) {
        RestResult result = mememberIntegralExchangeLog.updMemberIntegralInfo(request);
        return  result;
    }

    @Override
    public Integer getMemberIntegralInfo(String thirdUserId) {
        RestResult result = mememberIntegralExchangeLog.getMemberIntegralInfo(thirdUserId);
        log.info("Member getMemberIntegralInfo result={}",result);
        Integer integral = 0;
        if(null !=result.getData()){
            HashMap<String, Object> map = (HashMap<String, Object>) result.getData();
            integral = ((BigDecimal)map.get("integral")).intValue();
        }
        return integral;
    }
}
